﻿using UnityEngine;
using Network;
using TrueSync;

public class VisualMoveComponent : VisualComponent
{
    VisualEntity mVEntity;

    public void DoFixedUpdate(float deltaTime)
    {
    }

    public void DoUpdate(float deltaTime)
    {
    }

    public void Init(VisualEntity vEntity)
    {
        mVEntity = vEntity;
        mVEntity.RegistMsg((int)L2VMsgId.SetPosition, onVisualMove);
        mVEntity.RegistMsg((int)L2VMsgId.SetFaceDirection, setVisualFaceDirection);
    }

    public void OnDestroy()
    {
        mVEntity.UnregistMsg((int)L2VMsgId.SetPosition, onVisualMove);
        mVEntity.UnregistMsg((int)L2VMsgId.SetFaceDirection, setVisualFaceDirection);
    }

    public void Start()
    {
    }

    void onVisualMove(object[] content)
    {
        TSVector2 position = (TSVector2)content[0];
        mVEntity.transform.position = new Vector3(position.x.AsFloat(), position.y.AsFloat(), 0);
    }

    void setVisualFaceDirection(object[] content)
    {
        int faceRotation = (int)content[0];
        mVEntity.transform.localEulerAngles = new Vector3(0, faceRotation * 90, 0);
    }

}
